package com.yinhe.system.service.impl;

import com.yinhe.common.annotation.DataScope;
import com.yinhe.common.utils.DateUtils;
import com.yinhe.system.domain.YhRiskProject;
import com.yinhe.system.mapper.YhRiskProjectMapper;
import com.yinhe.system.service.IYhRiskProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.validation.Validator;
import java.util.List;

/**
 * 项目风险Service业务层处理
 * 
 * @author yinhe
 * @date 2022-07-13
 */
@Service
public class YhRiskProjectServiceImpl implements IYhRiskProjectService 
{
    @Autowired
    private YhRiskProjectMapper yhRiskProjectMapper;
    @Autowired
    protected Validator validator;

    /**
     * 查询项目风险
     * 
     * @param id 项目风险主键
     * @return 项目风险
     */
    @Override
    public YhRiskProject selectYhRiskProjectById(Long id)
    {
        return yhRiskProjectMapper.selectYhRiskProjectById(id);
    }

    /**
     * 查询项目风险列表
     * 
     * @param yhRiskProject 项目风险
     * @return 项目风险
     */
    @Override
    @DataScope(deptAlias = "p", userAlias = "p")
    public List<YhRiskProject> selectYhRiskProjectList(YhRiskProject yhRiskProject)
    {
        return yhRiskProjectMapper.selectYhRiskProjectList(yhRiskProject);
    }

    /**
     * 新增项目风险
     * 
     * @param yhRiskProject 项目风险
     * @return 结果
     */
    @Override
    public int insertYhRiskProject(YhRiskProject yhRiskProject)
    {
        yhRiskProject.setCreateTime(DateUtils.getNowDate());
        return yhRiskProjectMapper.insertYhRiskProject(yhRiskProject);
    }

    /**
     * 修改项目风险
     * 
     * @param yhRiskProject 项目风险
     * @return 结果
     */
    @Override
    public int updateYhRiskProject(YhRiskProject yhRiskProject)
    {
        yhRiskProject.setUpdateTime(DateUtils.getNowDate());
        return yhRiskProjectMapper.updateYhRiskProject(yhRiskProject);
    }

    /**
     * 批量删除项目风险
     * 
     * @param ids 需要删除的项目风险主键
     * @return 结果
     */
    @Override
    public int deleteYhRiskProjectByIds(Long[] ids)
    {
        return yhRiskProjectMapper.deleteYhRiskProjectByIds(ids);
    }

    /**
     * 删除项目风险信息
     * 
     * @param id 项目风险主键
     * @return 结果
     */
    @Override
    public int deleteYhRiskProjectById(Long id)
    {
        return yhRiskProjectMapper.deleteYhRiskProjectById(id);
    }

    /**
     * 导入项目风险数据
     *
     * @param userList 用户数据列表
     * @param isUpdateSupport 是否更新支持，如果已存在，则进行更新数据
     * @param operName 操作用户
     * @return 结果
     */
    @Override
    public String importRiskProject(List<YhRiskProject> riskProjectList, Boolean isUpdateSupport)
    {
        int successNum = 0;
        StringBuilder successMsg = new StringBuilder();
        StringBuilder failureMsg = new StringBuilder();
        for (YhRiskProject riskProject : riskProjectList) {
            long represent = Long.parseLong(riskProject.getRepresentativeOffice());
            riskProject.setDeptId(represent);
            this.insertYhRiskProject(riskProject);
            successNum++;
        }
        successMsg.insert(0, "恭喜您，数据已全部导入成功！共 " + successNum + " 条");
        return successMsg.toString();
    }
}
